<?php
require_once 'storage/CMdb.php';

class MPDOStorage {
	
	private static $conn;
	/**
	 *
	 * @param string $dsn
	 * @return PDO
	 */
	public static function instance($dsn = null){
		
		if(self::$conn === null):
			if($dsn === null)
				$dsn = CMdb::DSN_MAIN;
			
			try{
				self::$conn = new PDO($dsn);
			} catch (PDOException $po){
				echo $po;
			} catch (Exception $e){
				echo $e;
			}
		endif;
		
		return self::$conn;
	}

	public static function query($query=null){
		if($query===null)return false;
		
		if(self::$conn === null)self::$conn = MPDOStorage::instance();
		
		
		try{
			
			$stmt = self::$conn->query($query);
			
		}catch (PDOException $po){
			
			echo $po;
		}
		
		return $stmt; 
	}
	
	public function __clone(){
		throw new MException('This class can not be cloned');
	}
}
?>